In this article, I will show you how to access Microsoft database using OLEDB
data provider
Connection String:The ADO model uses the Connection String property to indicate the
OLEDB provider to use to connect to data store, along with the details needed
to complete the data connection.
A typical connection String has two parts:
Provider :< Provider name>; Data Source=<Source Details>
A valid connection for connecting to Microsoft Access database:
Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C: student.mdb
Used namespace: Imports System
Imports System.Data
Imports System.Data.OleDb Inserting data into MS Access Database by VB.NET 2005
Private Sub insert_Click(ByVal sender As System.Object,ByVal
e As System.EventArgs) Handles Insert.Click
Dim con As OleDbConnection
Dim sql,str As String
str = "Provider=Microsoft.Jet.oledb.4.0;Data Source=
C:student.mdb;"
con = New OleDbConnection(str)
sql = "insert into students(name,roll,mobile,email)
values('" & sname.Text & "','" & roll.Text & "',
'" & mobile.Text & "','"& email.Text & "')"
Dim cmd As OleDbCommand
Try
con.Open()
cmd = New OleDbCommand(sql, con)
cmd.ExecuteNonQuery()
sname.Text = ""
roll.Text = ""
mobile.Text = ""
email.Text = ""
MessageBox.Show("Insert Successfully")
con.Close()
Catch ex As OleDbException
MsgBox(ex.Message, MsgBoxStyle.Critical, "Oledb Error")
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "General Error")
End Try
End Sub
Posted by Dhilipkumar on September 29, 2008 at 10:43 am
hi friend…. thanks this code.. im new to vb.net….
im searchin here after a long time i got this code…
its very clear to me..
thank you…..
Posted by aladik on October 12, 2008 at 10:48 am
really it good, amazing website ,its easy to unterstand the new developer.
thanks many
Posted by Sudheesh k v on November 3, 2008 at 6:47 am
hi sabuj,
its very cool code snipet which could be useful for beginners like me
thanks dude
Posted by Invincibles on November 14, 2008 at 6:33 am
Hi Sabuj,
I thank you for this working code. I made some project that make use of the connection to the MSAccess database but I can’t figure it out until I tried your code.
Cheers =)
Posted by sabuj on November 15, 2008 at 4:55 am
If you fix a problem then u send problem ,try to solve that
Posted by Vijay Bhaskaran on December 18, 2008 at 5:29 am
Thank you to Sabujcse to provide the code to how to connect MSaccess to visual basic 2005..
Thank you once again
Posted by Nutthawut on January 8, 2010 at 2:46 pm
thank you very much
from Aof Thailand *-*
Posted by ramesh genwa on April 26, 2011 at 12:21 pm
Thanks you very much
I am seeking this type of solutiion.
thanks a lot..
Posted by Adin Okta Tjah Arpega on July 23, 2011 at 8:52 am
wow
Posted by nadel on August 10, 2011 at 3:46 am
ty 🙂
Posted by francis on August 17, 2011 at 5:50 am
thanks, this works…..nice site
Posted by Anandraj on September 27, 2011 at 7:01 am
Really nice….. It is easy to understand for easy developer.
Thank U…………
Posted by dani mfungo on June 12, 2012 at 1:09 am
i do appreciate
Posted by arun on August 29, 2012 at 6:18 pm
nice.. realy useful for me.. thanks for the provider
Posted by mahesh on September 15, 2012 at 6:37 am
Realy very nice…………………
Posted by udaykumar on January 10, 2013 at 1:59 am
thanx bro………..
Posted by mattress stores in miami on July 26, 2013 at 6:18 pm
Simply desire to say your article is as amazing.
The clarity in your post is just great and i can assume you’re an expert on this subject. Fine with your permission let me to grab your RSS feed to keep updated with forthcoming post. Thanks a million and please carry on the rewarding work.